package com.knife.bbs.object;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import com.knife.bbs.business.BBSDirService;
import com.knife.bbs.object.BBSDoc;
/**
 * BBS栏目
 */
public class BBSDir {
	
	//属性部份
    private String cid;
    private String sn;
    private String title;
    private String parentsn;
    private String dirpath;
    private String intro;
    private String tagimg;
    private String manager;
    private String submanager;
    private String vrtype;
    private String vrvalue;     
    private String inputuser;
    private Date inputtime; 
    private Integer sequence; 
    private Integer status;
    private int messagenum;
    private int replynum;
    private int todaynum;
    private BBSDoc lastdoc;
    
    private BBSDirService dirService=BBSDirService.getInstance();

    //getter及setter方法
	public String getCid() {
		return cid;
	}
	public void setCid(String cid) {
		this.cid = cid;
	}
	public String getDirpath() {
		return dirpath;
	}
	public void setDirpath(String dirPath) {
		this.dirpath = dirPath;
	}
	public Date getInputtime() {
		return inputtime;
	}
	public void setInputtime(Date inputTime) {
		this.inputtime = inputTime;
	}
	public String getInputuser() {
		return inputuser;
	}
	public void setInputuser(String inputUser) {
		this.inputuser = inputUser;
	}
	public String getIntro() {
		return intro;
	}
	public void setIntro(String intro) {
		this.intro = intro;
	}
	public String getManager() {
		return manager;
	}
	
	public void setManager(String manager) {
		this.manager = manager;
	}
	
	public String getParentsn() {
		return parentsn;
	}
	
	public void setParentsn(String parentSn) {
		this.parentsn = parentSn;
	}
	
	public Integer getSequence() {
		return sequence;
	}
	
	public void setSequence(Integer sequence) {
		this.sequence = sequence;
	}
	
	public String getSn() {
		return sn;
	}
	public void setSn(String sn) {
		this.sn = sn;
	}
	public Integer getStatus() {
		return status;
	}
	public void setStatus(Integer status) {
		this.status = status;
	}
	public String getSubmanager() {
		return submanager;
	}
	public void setSubmanager(String subManager) {
		this.submanager = subManager;
	}
	public String getTagimg() {
		return tagimg;
	}
	public void setTagimg(String tagImg) {
		this.tagimg = tagImg;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getVrtype() {
		return vrtype;
	}
	public void setVrtype(String type) {
		vrtype = type;
	}
	public String getVrvalue() {
		return vrvalue;
	}
	public void setVrvalue(String value) {
		vrvalue = value;
	}
	public int getMessagenum() {
		return messagenum;
	}
	public void setMessagenum(int messageNum) {
		this.messagenum = messageNum;
	}
	
	public int getReplynum() {
		return replynum;
	}
	
	public void setReplynum(int replyNum) {
		this.replynum = replyNum;
	}
	
	public int getTodaynum() {
		return todaynum;
	}
	
	public void setTodaynum(int todaynum) {
		this.todaynum = todaynum;
	}
	
	public BBSDoc getLastdoc() {
		return lastdoc;
	}
	
	public void setLastdoc(BBSDoc lastdoc) {
		this.lastdoc = lastdoc;
	}
	
	public BBSDir(com.knife.bbs.domain.BBSDir dir){
		this.cid=dir.getCid();
		this.dirpath=dir.getDirpath();
		this.inputtime=dir.getInputtime();
		this.inputuser=dir.getInputuser();
		this.intro=dir.getIntro();
		this.manager=dir.getManager();
		//this.messagenum=dir.getMessagenum();
		this.parentsn=dir.getParentsn();
		//this.replynum=dir.getReplynum();
		this.sequence=dir.getSequence();
		this.sn=dir.getSn();
		this.status=dir.getStatus();
		this.submanager=dir.getSubmanager();
		this.tagimg=dir.getTagimg();
		this.title=dir.getTitle();
		this.vrtype=dir.getVrtype();
		this.vrvalue=dir.getVrvalue();
		this.messagenum=dirService.messageNum(this.getSn());
		this.replynum=dirService.replyNum(this.getSn());
		this.todaynum=dirService.todayNum(this.getSn());
		this.lastdoc=dirService.getDirLastTopic(this.getSn());
	}
	
	public List<BBSDir> getChilds(){
		return dirService.getChildDirs(this);
	}
	
	private List<BBSDir> getParents(BBSDir dir){
		List<BBSDir> pList=new ArrayList<BBSDir>();
		BBSDir adir = dirService.getParentDir(dir);
		if(adir!=null){
			pList.add(adir);
			pList.addAll(getParents(adir));
		}
		return pList;
	}
	
	public List<BBSDir> getParents(){
		List<BBSDir> pList=getParents(this);
		Collections.reverse(pList);
		return pList;
	}
	
	public List<BBSDoc> getLastTopics(int num){
		return dirService.getDirLastTopics(this.getSn(),num);
	}
}
